package UIFree
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;

	public class uif_bitmap extends Bitmap {
		private var _runningProperty: Object;
		public var _data: Object;
		public function uif_bitmap(bitmapData:BitmapData=null, pixelSnapping:String='auto', smoothing:Boolean=false) {
			super(bitmapData, pixelSnapping, smoothing);
		}
		
		public function get position(): Point {
			return new Point(x, y);
		}
		
		public function set position(a_pos: Point): void {
			x = a_pos.x; 
			y = a_pos.y; 
		}
		
		public function pfx(propertyName: String, a_from: *, a_to:*, 
								a_transition: Function=null, fps: int =16, duration: int=500): FX {
			if (!_runningProperty) 
				_runningProperty = new Object();
			if (_runningProperty[propertyName]) {
				(_runningProperty[propertyName] as FX).cancel();
			}
			var _fx: FXContainer = new FXContainer(this, propertyName, a_from, a_to, 
								function(e: FXEvent): void {
				_runningProperty[propertyName].dispose();
				delete(_runningProperty[propertyName]);
			}, a_transition, fps, duration);
			
			_runningProperty[propertyName] = _fx;
			return _fx;
									
		}
		
		public function FXCancel(): void {
			for (var propertyName: String in _runningProperty) {
				(_runningProperty[propertyName] as FX).cancel();
				delete(_runningProperty[propertyName]);
			}
		}
		
		public function getFX(propertyName: String): FX {
			if (_runningProperty != null)
				return _runningProperty[propertyName] as FX;
			else return null;
		}
		
		public function remove(): void {
			if (parent) parent.removeChild(this);
		}
		
		public function get size(): Point {
			return new Point(width, height);
		}
		
		public function dispose(): void {
			remove();
			if (bitmapData) bitmapData.dispose();
		}
	}
}